<?php 

class category  {



	public function categorylist(){
		$result = DB::select('*')->from('syscategory')->execute()->as_array();
		return $result;
	}
	public function categoryByParent($id){
		$result = DB::select('*')->from('syscategory')->where("parentId","=",$id)->execute()->as_array();
		return $result;
	}
	public function category(){
		$result = DB::select('*')->from('syscategory')->where("parentId","=","0")->execute()->as_array();
		return $result;
	}
	public function add($parm){

		DB::insert("syscategory",array('name','sort','parentId'))->values(array($parm['name'],$parm['sort'],$parm['parentId']))->execute();

	}

	public function detail($id){
		$result = DB::select('*')->from('syscategory')->where("id","=",$id)->execute()->as_array();
		return $result;
	}
	public function updateStatus($parm){
		$status = null;
		if($parm['status'] == 1){
			$status = "未上架";
		}else{
			$status = "已上架";
		}
		DB::update("syscategory")->set(array('status'=>$status))->where('id','=',$parm['id'])->execute();
	}

	public function updateData($parm){

		DB::update("syscategory")->set(array('name'=>$parm['name'],'sort'=>$parm['sort']))->where('id','=',$parm['id'])->execute();
	}
}